<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    {#    <script src="dist/src/cos.js" type="text/javascript" charset="utf-8"></script>#}
    <script src="/static/dist/cos-js-sdk-v5.js"></script>
</head>
<body>
<input type="file" id="file-selector">
{#<input id="submitBtn" type="submit" value="上传">#}
<button id="submitBtn">上传</button>

<script>
    $(function () {
        var Bucket = 'sass-1300980145';
        var Region = 'ap-beijing';
        // 初始化实例
        var selectedFile;
        var filename;
        $("#file-selector").change(function () {
            selectedFile = document.getElementById('file-selector').files[0];
            filename = selectedFile.name;
            console.log(filename)
        });
        $("#submitBtn").click(function () {
            var cos = new COS({
                getAuthorization: function (options, callback) {
                    // 异步获取临时密钥
                    $.get('http://127.0.0.1:8000/app02/send', {}, function (data) {
                        var credentials = data && data.credentials;
                        console.log(credentials);
                        if (!data || !credentials) return console.error('credentials invalid');
                        callback({
                            TmpSecretId: credentials.tmpSecretId,
                            TmpSecretKey: credentials.tmpSecretKey,
                            XCosSecurityToken: credentials.sessionToken,
                            // 建议返回服务器时间作为签名的开始时间，避免用户浏览器本地时间偏差过大导致签名错误
                            StartTime: data.startTime, // 时间戳，单位秒，如：1580000000
                            ExpiredTime: data.expiredTime, // 时间戳，单位秒，如：1580000900
                        });


                    });
                }
            });

        });
    })


</script>

</body>
</html>